<?php

	/**
	 * <version greek="beta" major="1" minor="0">Cochin Splash Hen</version>
	 * <author email="njones@art-k-tec.com">Nika Jones</author>
	 * <copyright start="2007">Art-k-tec Systems, LLC</copyright>
	 * <license type="Apache2.0" href="http://www.opensource.org/licenses/apache2.0.php">Apache License, Version 2.0</license>
	 */
	class bBitwiseException extends Exception {
		const INVALID =10000;
	}
	
	interface IBitwise {
		
		public static function Init();
		public static function MakeInstance();
	}
	
	abstract class bBitwise implements IBitwise {
		const NULL ="\0\0\r\n\0\0";
		private static $aBits;
		
		private $aValue;
		private $aBitwise;
		
		private static $nMajor =1;
		private static $nMinor =0;
		private static $sRevision ="0000";
		
		public static function _version_() { return self::$nMajor.'.'.self::$nMinor.'.'.self::$sRevision; }
		
		/// <summary>
		/// 	Instanciates a class for a particular variable.
		/// 	Note, this variable must be set up before hand in the class
		/// 	which is extending the bBitwise class.
		/// <summary>
		/// <param type="string" name="sClass">The name of the extending class, --this is due to a bug in PHP</param>
		/// <param type="string" name="sVariable">The variable to add the instance of the class to.</param>
		/// <returns type="integer" />
		public static function MakeInstance($sClass =__CLASS__) {
			
			if(self::$aBits ==null) {
				$a[0] =0;
				$a[1] =1;
				for($i =2; $i <32; $i++) {

					$a[$i] =($a[$i-1] * 2);
				}

				self::$aBits =$a;
			}
			
			return new $sClass();
		}
		
		///<summary>
		///		Intercepts the method call, and sets the value of the
		///		bitwise constant or returns the value if no parameters passed
		///</summary>
		public function __call($sMethodName, $aValues) {
			
			if(!isset($this->aBitwise[$sMethodName])) {
				
				$this->aBitwise[$sMethodName] =self::$aBits[count($this->aBitwise)];
			}
			
			if(!empty($aValues))
			{
				$this->aValue[$sMethodName] =$aValues[0]; //only take first arg
			} else {
				
				if(!isset($this->aValue[$sMethodName])) {
					
					$this->aValue[$sMethodName] =null;
				}
			}
			
			return $this->aValue[$sMethodName];
		}
		
		///<summary>
		///		Intercepts the setter of the value sets the bitwise
		///		value of the constant
		///</summary>
		public function __set($sVariableName, $sValue) {
			
			if(!isset($this->aBitwise[$sVariableName])) {
				
				$this->{$sVariableName}($sValue);
				$nReturn =$this->aBitwise[$sVariableName];
			}
		}
		
		///<summary>
		///		Intercepts the getter of the value and returns
		///		the bitwise value of the constant. Also allows
		///		the init of a new constant.
		///</summary>
		public function __get($sVariableName) {
			
			if(isset($this->aBitwise[$sVariableName])) {
				
				$nReturn =$this->aBitwise[$sVariableName]; 
			} else {
				
				$this->{$sVariableName}();
				$nReturn =$this->aBitwise[$sVariableName];
			}
			
			return $nReturn;
		}
	}
?>
<?php return; ?>
<bResourceManager version="1.0">
	<summary 
		name="bBitwise"
		version="1.0" 
		checksum="none" 
		signed="http://www.art-k-tec.com/libs/signatures/bBitwise"
		copyright="2007 art-k-tec systems, llc"
	>
		First resource management package. It's intended to be generic so it can be used in a wide
		variety of PHP projects.
	</summary>
</bResourceManager>